package com.cms.controller.front.member;

import com.cms.Feedback;
import com.cms.controller.front.BaseController;
import com.cms.entity.Log;
import com.cms.entity.Member;
import com.cms.entity.Money;
import com.cms.routes.RouteMapping;

import java.math.BigDecimal;

/**
 * Controller - 首页
 *
 *
 *
 */
@RouteMapping(url = "/member")
public class IndexController extends BaseController{


	public void index(){
        Member currentMember = getCurrentMember();
        Money money=new Money().dao().findById(currentMember.getId());
        setAttr("money", money);
	    render("/templates/"+getTheme()+"/"+getDevice()+"/member.html");
	}

    public void list(){
        Integer pageNumber = getParaToInt("pageNumber");
        String status = getPara("status");
        if(pageNumber==null){
            pageNumber=1;
        }
        int pageSize = 20 ;
        Member currentMember = getCurrentMember();
        setAttr("page", new Member().dao().findUserPage(currentMember.getId().toString(),pageNumber,pageSize));
        render("/templates/"+getTheme()+"/"+getDevice()+"/memberList.html");
    }

    public void cash(){
        Member currentMember = getCurrentMember();
        Money money=new Money().dao().findById(currentMember.getId());
        setAttr("money", money);
        render("/templates/"+getTheme()+"/"+getDevice()+"/cash.html");
    }

    public void cashApply(){
        String cashMoney = getPara("money");
        Member currentMember = getCurrentMember();
        Money money=new Money().dao().findById(currentMember.getId());
        new Money().dao().cash(currentMember.getId(), BigDecimal.ZERO.subtract(new BigDecimal(cashMoney)),"提现申请");

        setAttr("feedback", Feedback.success("提现成功"));
        redirect("/member");
    }

}
